<div class="promotion">
	<!-- banner-->
	<section class="bannerarea">
		<div class="bannerimg"><img src="images/show/suyun/banner.png" class="img-responsive" alt="Responsive image"></div>
	</section>
	<!-- maincontent-->
	<section class="container">
		<div ng-controller="ctrlRead">
			<table class="table table-striped table-condensed table-hover">
				<tbody ng-app="pagedataApp" ng-controller="pagedataCrtl">
					<div class="activitybox row">
						<div class="areatitle">
							<h2 class="text-left"><span class="title">活动促销</span></h2>
							<p class="english"><span class="subtitle">ACTIVITY PROMOTION</span></p>
							<ul class="list-inline">
								<li class="active">全国</li>
								<li>华中</li>
								<li>华南</li>
								<li>华北</li>
							</ul>
						</div>
						<div class="col-sm-6 col-md-3" ng-repeat="promotion in promotions">
							<div class="thumbnail">
								<img ng-src="{{promotion.titleImg}}" alt="活动一">

								<div class="caption">
									<p>
										<a href="#/promotion_detail">{{promotion.title}}</a>
									</p>
									<p class="text-right status">
										<span>进行中</span>
									</p>
									<p class="text-right grey">{{promotion.startDate}}—{{promotion.endDate}}</p>
									<p class="text-right grey">{{promotion.activeScope}}</p>
								</div>
							</div>
						</div>
					</div>
				</tbody>
			</table>
			<!--  分页按钮 -->
			<div>
				<ul class="pagination pull-right">
					<li>
						<a href ng-click="prev()">上一页</a>
					</li>
					<li ng-repeat="page in pageList" ng-class="{active: isActivePage(page)}">
						<a ng-click="selectPage(page)">{{ page }}</a>
					</li>
					<li>
						<a href ng-click="next()">下一页</a>
					</li>
				</ul>
			</div>
		</div>
	</section>
	<script>
		var pagedataApp = angular.module("pagedataApp", []);
		pagedataApp.controller("pagedataCtrl", ["$scope", "$http",
			function($scope, $http) {
				//分页组件
				$scope.currentPage = 1;
				$scope.pageSize = 4;
				$scope.totalCount = 0;
				$scope.totalPage = 0;
				$scope.pageList = new Array();
				//分页函数
				$scope.prove = function() {
					$scope.selectPage($scope.currentPage - 1);
				}
				$scope.next = function() {
					$scope.selectPage($scope.currentPage + 1);
				}
				$scope.isActivePage = function(page) {
					return(page === $scope.currentPage);
				}
				$scope.selectPage = function(page) {
					$http({
						method: 'GET',
						url: './promotion_pagedata.action',
						params: {
							"page" : page,
							"rows" : $scope.pageSize
						}
					}).success(Function(data, status, headers, config) {
						$scope.promotions = data.pageData;
						$scope.totalCount = data.totalCount;
						$scope.totalPage = Math.ceil($scope.totalCount/$scope.pageSize);
						$scope.currentPage =  page;
						var begin = 0;
						var end = 0;
						//理论上begin为当前页减5
						begin = $scope.currentPage-5;
						if(begin<1){
							begin=1;
						}
						end = begin+9;
						if(end>$scope.totalPage){
							end = $scope.totalPage;
						}
						begin = end-9;
						if(begin<1){
							begin = 1;
						}
						for(var i = begin; i<end; i++){
							$scope.pageList.push(i);
						}
						
					}).error(Function(data, status, headers, config) {
						alert("出错,请联系管理員");
					});

				}
				$scope.selectPage(1);

			}
		]);
	</script>
</div>